<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%--
  Created by IntelliJ IDEA.
  User: Yuzhihao
  Date: 2021/10/24
  Time: 19:34
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>选择服务项目</title>
    <link type="text/css" rel="stylesheet" href="fontsawesome/css/font-awesome.css"/>
    <link type="text/css" rel="stylesheet" href="css/style.css"/>
</head>
<body>
<div class="main_box">
    <div class="cont_box editpro_box">
        <form action="#" method="post" id="choose_form">
            <ul class="addpro_box">
                <li>
                    <label>服务选择：</label>
                    <select  name="serve"  data-msg-required="请选择服务">
                        <option>请选择</option>
                        <!--这里value为服务的id-->
                        <c:forEach items="${all}" var="all1">
                        <option value="${all1.sid}" rete-price="${all1.ac_price}" data-price="${all1.price}">${all1.serv}</option>
                        </c:forEach>
<%--                        <option value="2">房车清洗</option>--%>
<%--                        <option value="3">驾驶舱气触媒空气治理A+雾化气触媒B+消毒车美容人健康</option>--%>
<%--                        <option value="4">喷晶镀膜（比封釉更经济实惠的镀膜，快速施工）</option>--%>
                        <select>
                </li>
                <li>
                    <label>属性：</label>
                    <div class="f_left choose_span choose_radio" id="models">
                        <!--这里span需要传车型的id-->
                        <c:forEach items="${car_ps}" var="car_">
                        <span>${car_.c_Name}</span>
                        </c:forEach>
<%--                        <span>SUV</span>--%>
<%--                        <span>商务车</span>--%>
                    </div>
                    <input type="hidden" name="model" required data-msg-required="请选择爱车属性"/>
                </li>
                <li>
                    <label>施工：</label>
                    <div class="f_left choose_span choose_check" id="workers">
                        <!--这里span需要传施工的id-->
                        <c:forEach items="${Sersg}" var="Sersg22">
                        <span id="${Sersg22.staff_id}">${Sersg22.s_name}</span>
                        </c:forEach>
<%--                        <span id="111">陈二</span>--%>
<%--                        <span id="222">张三</span>--%>
<%--                        <span>李四</span>--%>
<%--                        <span>王五</span>--%>
<%--                        <span>赵六</span>--%>
<%--                        <span>孙七</span>--%>
<%--                        <span>周八</span>--%>
<%--                        <span>吴九</span>--%>
                    </div>
                    <input type="hidden" name="workers" required data-msg-required="请选择施工人员"/>
                </li>
                <li>
                    <label>销售：</label>
                    <div class="f_left choose_span choose_radio" id="staff">
                        <!--这里span需要传销售的id-->
                        <c:forEach items="${Serxs}" var="Serxs333">
                        <span id="${Serxs333.staff_id}">${Serxs333.s_name}</span>
                        </c:forEach>

                    </div>
                </li>
            </ul>
            <div class="probtn_box clearfix">
                <input type="button" value="确认选择" class="btn blue_btn"/>
            </div>
        </form>
    </div>
</div>
<!--javascript include-->
<script src="js/jquery-2.2.1.min.js"></script>
<script src="js/jquery.dataTables.min.js"></script>
<script src="js/bootstrap-datepicker.js"></script>
<script src="js/jquery.validate.min.js"></script>
<script src="js/other.js"></script>

<script>
    $(function(){
        var Wparent = window.parent.document,
            tipBg = "<div class='tip_bg tipbg_top'></div>",
            tipBox = "<div class='tip_box tipbox_top'></div>";
        //=====弹出窗设置
        function DelTipWidth(Twidth,Theight){
            $(".tipbox_top",Wparent).css({"width":Twidth+"px","height":Theight+"px","margin-top":-(Theight/2)+"px","margin-left":-(Twidth/2)+"px"});
            $(".tip_close",Wparent).on("click",Tipclose);
        }
        //=====关闭弹出窗
        function Tipclose(){
            $(".tipbox_top",Wparent).remove(); //移除新增的外层className
            $(".tipbg_top",Wparent).remove(); //移除新增的背景className
        }
        //=====成功提示
        function Success(obj){
            $(".tipbox_top:last",Wparent).css({"width":"400px","height":"180px","margin-top":"-90px","margin-left":"-200px","z-index":"198611060"});
            $(".tip_close",Wparent).on("click",function(){
                if(obj==200){
                    Tipclose();
                    //关闭选服务页面
                    $(".tip_bg",Wparent).remove();
                    $(".tip_box",Wparent).remove();
                }else if(state!=200){
                    Tipclose();
                }
            });
        }
        $(".choose_radio span").click(function(){
            if($(this).hasClass("curr")){
                $(this).removeClass("curr");
            }else{
                $(this).addClass("curr").siblings().removeClass("curr");
            }
            $(this).parent().next().val($(this).parent().find(".curr").text());
        });
        $(".choose_check span").click(function(){
            if($(this).hasClass("curr")){
                $(this).removeClass("curr");
            }else{
                $(this).addClass("curr");
            }
            $(this).parent().next().val($(this).parent().find(".curr").text());
        });
        $("#choose_form").validate({
            ignore:[],
            errorElement:"div"
        });
        //提交
        $(".btn").click(function(){
            var Wparent = window.parent.document,
                flag = $("#choose_form").valid();
            if (!flag) {
                //alert("没有通过验证");
                return;
            }else{
                var data,arr = [],
                    userInfo = $("iframe[name='cont_box']",Wparent).contents().find(".user_have table tr:first td input[name='m_id']").val(),
                    serve = $("select[name='serve']").find("option:selected").text(),
                    serveId = $("select[name='serve']").find("option:selected").val(),
                    models = $("#models").find(".curr").text(),
                    modelsId = $("#models").find(".curr").prop("id"),
                    staff = $("#staff").find(".curr").text(),
                    staffId = $("#staff").find(".curr").prop("id");

                $("#workers .curr").each(function(){
                    var workArr = $(this).prop("id");
                    arr.push(workArr);
                });
                if(userInfo=="undefind"){
                    data = {
                        "severId":serveId, //服务id
                        "modelsId":modelsId, //车型id
                        "workersId":arr, //施工人员id
                        "staffId":$("#staff").find(".curr").prop("id") //销售id
                    };
                }else{
                    data = {
                        "userId":userInfo, //会员id
                        "codeId":$("iframe[name='cont_box']",Wparent).contents().find(".car_row .curr").attr("code-id"), //车牌号
                        "severId":serveId, //服务id
                        "modelsId":modelsId, //车型id
                        "workersId":arr, //施工人员id
                        "staffId":$("#staff").find(".curr").prop("id") //销售id
                    };
                }
                $.ajax({
                    type:"post",
                    url:"#",
                    data:data,
                    success:function(result){

                        var result = {status:"200",price:"2000",total:"100"};//测试数据，使用时请删除
                        var state = result.status;
                        if(state == 200){
                            //为主页面添加所选服务
                            var html,arrText = [],workers,
                                price = $("select[name='serve']").find("option:selected").attr("data-price"),
                                rates = $("select[name='serve']").find("option:selected").attr("rete-price");
                            if(staff==null||staff==""||staff=="undefined"){
                                staff="-";
                            }
                            if(models==null||models==""||models=="undefined"){
                                models="-";
                            }
                            if(modelsId==null||modelsId==""||modelsId=="undefined"){
                                modelsId="";
                            }
                            if(staffId==null||staffId==""||staffId=="undefined"){
                                staffId="";
                            }
                            $("#workers .curr").each(function(){
                                arrText.push($(this).text());
                            });
                            workers = arrText.join("、");
                            html = "<li class='data_serve'><span>"+serve+"</span>，本项服务价值<em class='sever_pic'>"+price+"元</em>，会员价格<em class='sever_upic'>"+rates+"元</em>，属性：<span>"+models+"</span>，施工：<span>"+workers+"</span>，销售：<span>"+staff+"</span><span class='del_spend'>删除<i class='fa fa-close'></i></span></li>";
                            $("iframe[name='cont_box']",Wparent).contents().find(".spend_info ul").append(html);
                            var list = $("iframe[name='cont_box']",Wparent).contents().find(".spend_info ul li"),
                                picArr = [0,0],total,totalu;
                            $(list).each(function(){
                                var goodsPic = $(this).find(".goods_pic").text(),
                                    severPic = $(this).find(".sever_pic").text(),
                                    severUpic = $(this).find(".sever_upic").text();
                                if(goodsPic==null||goodsPic=="undefind"||goodsPic==""){
                                    goodsPic = 0;
                                }
                                if(severPic==null||severPic=="undefind"||severPic==""){
                                    severPic = 0;
                                }
                                if(severUpic==null||severUpic=="undefind"||severUpic==""){
                                    severUpic = 0;
                                }
                                total = parseInt(goodsPic)+parseInt(severPic);
                                totalu = parseInt(goodsPic)+parseInt(severUpic);
                                totalAll = picArr[0]+total;
                                totaluAll = picArr[1]+totalu;
                                picArr = [totalAll,totaluAll];
                            });
                            $("iframe[name='cont_box']",Wparent).contents().find(".spend_info .totalpic").text(picArr[0]+"元");
                            $("iframe[name='cont_box']",Wparent).contents().find(".spend_info .totalupic").text(picArr[1]+"元");
                            $("iframe[name='cont_box']",Wparent).contents().find(".spend_info",Wparent).show();
                            var serveData = {"serveId":serveId,"modelsId":modelsId,"staffId":staffId,"workersId":arr};
                            window.parent.frames["cont_box"].serveData.push(serveData);
                            //关闭选服务页面
                            $(".tip_bg",Wparent).remove();
                            $(".tip_box",Wparent).remove();
                        }else{
                            var errorTxt = "<p class='del_info'>保存失败，请重试</p><div class='tip_btnbox'><button class='btn btn_dsure tip_close'>确认</button></div>";
                            $("body",Wparent).append(tipBg);
                            $("body",Wparent).append(tipBox);
                            $(".tipbox_top",Wparent).append(errorTxt);
                            Success(state);
                        }
                    },
                    error:function(errormsg){
                        var errorTxt = "<p class='del_info'>操作失败，请重试</p><div class='tip_btnbox'><button class='btn btn_dsure tip_close'>确认</button></div>";
                        $("body",Wparent).append(tipBg);
                        $("body",Wparent).append(tipBox);
                        $(".tipbox_top",Wparent).append(errorTxt);
                        Success(500);
                    }
                });
            };

        });
    });
</script>
</body>
</html>

